package cn.com.waajyun.shanbayscan.core;

import cn.com.waajyun.shanbayscan.cache.CacheMap;
import cn.com.waajyun.shanbayscan.dto.ArticleDto;
import cn.com.waajyun.shanbayscan.service.ArticleService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @Author: Feng
 * @Date: 2018/12/25 9:42
 */
@Component
public class ShanbayApplicationRunner implements ApplicationRunner {

    private final Log LOG = LogFactory.getLog(ShanbayApplicationRunner.class);

    @Autowired
    private ArticleService articleService;

    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        CacheMap.put("cachedArticles", articleService.getPageContent(1, null, true));
        LOG.info("初始化数据成功，共条数：" + ((List<ArticleDto>)CacheMap.get("cachedArticles")).size());
        CacheMap.put("updateCacheTime", new Date());
    }
}
